/*
 *  OpenVPN -- An application to securely tunnel IP networks
 *             over a single TCP/UDP port, with support for SSL/TLS-based
 *             session authentication and key exchange,
 *             packet encryption, packet authentication, and
 *             packet compression.
 *
 *  Copyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef OPENVPN_SOCKET_H
#define OPENVPN_SOCKET_H

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#define SOCK_PATH "/data/service/el1/public/netmanager/openvpn"
#define BUFFER_SIZE 256
#define SIGTERM 15
#define OPENVPN_STATE_UNKNOWN 100
#define OPENVPN_STATE_CONNECTED 104
#define OPENVPN_STATE_DISCONNECTED 105

#define CONFIG_ERROR_PRIVATE_KEY 200
#define CONFIG_ERROR_CLIENT_CRT 201
#define CONFIG_ERROR_CA_CRT 202
#define CONFIG_ERROR_TIME_OUT 203


int setupClientSocket();
int setVpnAddress(char *ip);
void setupIfconfig(char *ifconfig, char *netmask, int mtu);
void setupRoute(char *dnsAddress);
int addroute(char *route);
void updateOpenVpnState(int state);
void report_config_err(int err_code);


void *readMsg(void *arg);
void sendMessage(char *buffer);
#endif /* OPENVPN_SOCKET_H */